var deleteID = '';
var vm = new Vue({
    el: "#app",
    data:
        {
            pageModel: '',
            messages: '',
            title: '',
            sender: '',
            receiver: '',
        },
    // 方法存放区
    methods: {
        send() {
            axios({
                method: 'POST',
                url: '/allMessage/getList'
            }).then(function (res) {
                vm.pageModel = res.data;
                vm.messages = res.data.data;
                // console.log(vm.pageModel)
            }).catch(function (reason) {
                console.log(reason);
            })
        },
        // 删除
        delectCheck(informationId) {
            deleteID = informationId
            $(".tip").fadeIn(200);
        },
        // 查询留言
        getOne(informationId) {
            window.location.href = "http://localhost:8099/allMessage/getById/" + informationId
        },
        // 回复留言
        updateMessage(informationId) {
            window.location.href = "replyMessage.html?no=" + informationId
        },
        // 删除确认
        delectCheck2() {
            axios.post('http://localhost:8099/allMessage/delete/' + deleteID)
                .then(function (response) {
                    alert(response.data)
                    vm.send()
                })
                .catch(function (error) {
                    alert(response.data)
                });
        },//点击分页
        clickPageModel(num) {
            var s1 = $("input[name='messageIntro']").val();
            var s2 = $("input[name='sender']").val();
            var s3 = $("input[name='accept']").val();
            axios({
                method: 'POST',
                url: 'http://localhost:8099/allMessage/getPage',
                params: {
                    "title": s1,
                    "sender":s2,
                    "receiver":s3,
                    "pageNum": num
                }
            }).then(function (res) {
                vm.pageModel = res.data;
                vm.messages = res.data.data;
                console.log(vm.pageModel)
            }).catch(function (reason) {
                console.log(reason);
            })

    },
    getByCondition() {
        var s1 = $("input[name='messageIntro']").val();
        var s2 = $("input[name='sender']").val();
        var s3 = $("input[name='accept']").val();
        if (s1 == '' && s2 == '' && s3 == '') {
            alert("请选择条件");
        } else {
            axios({
                method: 'POST',
                url: 'http://localhost:8099/allMessage/getPage',
                params: {
                    "title": s1,
                    "sender":s2,
                    "receiver":s3,
                }
            }).then(function (res) {
                vm.pageModel = res.data;
                vm.messages = res.data.data;
                if(vm.pageModel.totalRows==0){
                    alert("没有相关信息")
                }
            }).catch(function (reason) {
                console.log(reason);
            })
        }
    },
    },
    //页面加载完自动执行
    mounted() {
        this.send();
    }
});





